﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using WooCoo.ObjectModel;
using WooCoo.Portal.Contracts;

namespace WooCoo.Portal.Service
{
    [Export("WooCoo.Portal.Contracts.ISupportService")]
    public class SupportService : ISupportService
    {
        /// <summary>
        /// 获取哈希参数值，还需要再进行优化，至少缓存->数据库
        /// </summary>
        /// <param name="hashType"></param>
        /// <param name="hashKey"></param>
        /// <returns></returns>
        public string GetHashParameter(string hashType, string hashKey)
        {
            var sypt = (RepositoryFactoryHost.Factory.GetRepository<SysParameterType>().AsQueryable());
            var query = from p in RepositoryFactoryHost.Factory.GetRepository<SysParameter>().AsQueryable()
                        from ptype in sypt
                        where p.ParameterTypeID == ptype.ID && p.ParameterName == hashKey && ptype.TypeCode == hashType
                        select p.ParameterCode;
            return query.FirstOrDefault();
        }


        public IList<SysResource> GetUserMenuResource(string usercode)
        {
            var query = from res in RepositoryFactoryHost.Factory.GetRepository<SysResource>().AsQueryable()
                        orderby res.SortIndexPath
                        select res;
            return query.ToList();     
        }
    }
}
